package tech.aistar.controller.noteshow;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import tech.aistar.util.UploadImg.QiniuCloudUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**图片上传类
 * Created by Dell on 2019/10/8.
 */
@Controller
@SuppressWarnings("all")
public class UploadImgController {



    @RequestMapping("/img")
    public String upload(){
        return "traveler_show/picture_upload";
    }

    @RequestMapping("/upload")
    @ResponseBody
    public Map upload(MultipartFile myfile) {
        Map<String,String> map = new HashMap<>();

        try {
            String imgUrl = QiniuCloudUtil.upload(myfile.getBytes(),myfile.getOriginalFilename());
            map.put("imgUrl", imgUrl);

        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);

        }
        //因为要作为结果返回
        return map;

    }
/**
 * @Description:第二个富文本
 * @param:
 * @author XiaoDi
 * @date 2019/10/9 13:52
*/
    @RequestMapping("/upload_two")
    @ResponseBody
    public Map upload2(MultipartFile myfile2) {
        Map<String,String> map = new HashMap<>();

        try {
            String imgUrl = QiniuCloudUtil.upload(myfile2.getBytes(),myfile2.getOriginalFilename());
            map.put("imgUrl", imgUrl);

        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);

        }
        //因为要作为结果返回
        return map;

    }

    /**
     * @Description:第三个富文本
     * @param:
     * @author XiaoDi
     * @date 2019/10/9 13:53
    */
    @RequestMapping("/upload_three")
    @ResponseBody
    public Map upload3(MultipartFile myfile3) {
        Map<String,String> map = new HashMap<>();

        try {
            String imgUrl = QiniuCloudUtil.upload(myfile3.getBytes(),myfile3.getOriginalFilename());
            map.put("imgUrl", imgUrl);

        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);

        }
        //因为要作为结果返回
        return map;

    }

    /**
     * @Description:第四个富文本
     * @param:
     * @author XiaoDi
     * @date 2019/10/9 13:53
    */
    @RequestMapping("/upload_four")
    @ResponseBody
    public Map upload4(MultipartFile myfile4) {
        Map<String,String> map = new HashMap<>();

        try {
            String imgUrl = QiniuCloudUtil.upload(myfile4.getBytes(),myfile4.getOriginalFilename());
            map.put("imgUrl", imgUrl);

        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);

        }
        //因为要作为结果返回
        return map;

    }
}


